package com.liao.content.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.liao.content.model.dto.CategoryInfo;
import com.liao.content.model.po.MovieCategory;
import com.liao.content.service.MovieCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 电影分类表 前端控制器
 * </p>
 *
 * @author liao
 */
@Slf4j
@RestController
@RequestMapping("movieCategory")
public class MovieCategoryController {

    @Autowired
    private MovieCategoryService movieCategoryService;



    /**
     * @description: 根据id查出电影的分类信息
     * @author liao
     * @date 2023/7/22 14:35
     * @version 1.0
     * @return
     */
    @GetMapping("/getmovieCategory")
    public CategoryInfo movieCategory(@Param("categoryId") String categoryId){
        LambdaQueryWrapper<MovieCategory> info = new LambdaQueryWrapper<MovieCategory>().eq(MovieCategory::getId, categoryId);
        LambdaQueryWrapper<MovieCategory> childrenInfo = new LambdaQueryWrapper<MovieCategory>().eq(MovieCategory::getParentid, categoryId);

        MovieCategory one = movieCategoryService.getOne(info);
        CategoryInfo categoryInfo=new CategoryInfo();

        List<MovieCategory> list = movieCategoryService.list(childrenInfo);


        BeanUtils.copyProperties(one,categoryInfo);
        categoryInfo.setChildren(list);
        return categoryInfo;

    }


    /**
     * @description: 根据id查出电影的基本信息
     * @author liao
     * @date 2023/7/22 14:35
     * @version 1.0
     * @return
     */
    @GetMapping("/getmovieCategoryById")
    public MovieCategory movieCategoryById(@Param("categoryId") String categoryId) {
        LambdaQueryWrapper<MovieCategory> info = new LambdaQueryWrapper<MovieCategory>().eq(MovieCategory::getId, categoryId);
        MovieCategory one = movieCategoryService.getOne(info);
        return one;

    }

}
